﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NHADAT
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            char[] character = { '/' };

            if (Request["ReturnUrl"] != null)
            {
                // Request["ReturnUrl"].ToString() -> 
                // http://localhost:1965/Admin/Login.aspx;
                // http://localhost:1965/Customer/Login.aspx

                string[] strs = Request["ReturnUrl"].Split(character);

                // if the second part is Admin go to admin login
                if (strs[1].ToLower() == "admincp")
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                        Response.Redirect(@"/");
                    else
                        Response.Redirect(@"/AdminCP/Login.aspx?ReturnUrl=" + Request["ReturnUrl"].ToString());
                }
                else
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                        Response.Redirect(@"/");
                    else
                        Response.Redirect(@"/Account/Login?ReturnUrl=" + Request["ReturnUrl"].ToString());
                }
            }
            else
            {
                Response.Redirect(@"/Account/Login");
            }
        }
    }
}